/*
 * Copyright 2020-2021 redragon.dongbin
 *
 * This file is part of redragon-erp/赤龙ERP.

 * redragon-erp/赤龙ERP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * redragon-erp/赤龙ERP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with redragon-erp/赤龙ERP.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.erp.inv.input.dao.model;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import com.erp.masterdata.common.model.BaseModel;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Data
@MappedSuperclass
public class InvInputLineBase extends BaseModel {

    //Constructors
    public InvInputLineBase() {
    }
    
    //Fields
    
    //主键
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "input_line_id", unique = true, nullable = false)
    private Integer inputLineId;

    //入库行编码
    @NotBlank(message="入库行编码不能为空")
    @Column(name = "input_line_code", unique = true, nullable = false, length = 45)
    private String inputLineCode;

    //入库头编码
    @Column(name = "input_head_code", unique = false, nullable = false, length = 45)
    private String inputHeadCode;

    //入库来源行编码（采购订单行编码）
    //@NotBlank(message="来源单据行编码不能为空")
    @Column(name = "input_source_line_code", unique = false, nullable = false, length = 45)
    private String inputSourceLineCode;

    //物料编码
    @NotBlank(message="物料编码不能为空")
    @Column(name = "material_code", unique = false, nullable = false, length = 45)
    private String materialCode;
    //发货单数量
    @NotNull(message="入库数量不能为空")
    @Column(name = "quantity", unique = false, nullable = false,length = 10)
    private BigDecimal quantity;
    //入库数量
    @NotNull(message="入库数量不能为空")
    @Column(name = "input_quantity", unique = false, nullable = false,length = 10)
    private BigDecimal inputQuantity;

    //单价
    @Column(name = "price", unique = false, nullable = true,length = 10)
    private BigDecimal price;
    
    public BigDecimal getPrice() {
        if(this.price!=null) {
            return this.price;
        }else if(this.getPoPrice()!=null){
            return this.getPoPrice();
        }

        return null;
    }

    //金额
    @Column(name = "amount", unique = false, nullable = true,length = 10)
    private BigDecimal amount;
    
    public BigDecimal getAmount() {
        if(this.amount!=null) {
            return this.amount;
        }else if(this.getPoLineAmount()!=null){
            return this.getPoLineAmount();
        }
        
        return null;
    }

    //赠送数量
    @Column(name = "attached" , unique = false, nullable = true, length = 45)
    private String attached;

    //赠送说明
    @Column(name = "attached_memo", unique = false, nullable = true, length = 255)
    private String attachedMemo;

    //损耗数量
    @Column(name = "loss", unique = false, nullable = true, length = 45)
    private String loss;

    //损耗说明
    @Column(name = "loss_memo", unique = false, nullable = true, length = 255)
    private String lossMemo;

    //折扣
    @Column(name = "discount", unique = false, nullable = true, length = 45)
    private String discount;

    //折扣原因
    @Column(name = "discount_memo",unique = false, nullable = true, length = 255)
    private String discountMemo;



    //是否有质检报告
    @Column(name = "is_Report", unique = false, nullable = true, length = 2)
    private String isReport;
    //库存方式
    @Column(name = "inv_means", unique = false, nullable = true, length = 2)
    private String invMeans;

    //单位
    @Column(name = "unit", unique = false, nullable = true, length = 45)
    private String unit;
    
    public String getUnit() {
        if(StringUtils.isNotBlank(this.unit)) {
            return this.unit;
        }else if(StringUtils.isNotBlank(this.getPoUnit())) {
            return this.getPoUnit();
        }
        
        return null;
    }

    //备注
    @Column(name = "memo", unique = false, nullable = true, length = 200)
    private String memo;

    //版本
    @Column(name = "version", unique = false, nullable = false)
    private Integer version;

    //状态
    @Column(name = "status", unique = false, nullable = false, length = 10)
    private String status;


    
    /*
     * 用于显示的字段
     */
    @Transient
    private String materialName;
    @Transient
    private String materialStandard;
    @Transient
    private BigDecimal poPrice;

    @Transient
    private BigDecimal inputedQuantity;
    @Transient
    private String poUnit;
    @Transient
    private BigDecimal poLineAmount;
    @Transient
    private String headInputType;
}